<?php

class ArticlesController extends Controller
{
	var $_model;
	var $pageTitle = 'Автодинамика - Новости';
	var $page_id = 'page1';

	public function actionIndex()
	{
		$criteria=new CDbCriteria(array(
			'condition'=>'publicated < now()',
			'order'=>'publicated DESC',
		));
		if(isset($_GET['tag']))
			$criteria->addSearchCondition('tags',$_GET['tag']);
	 
		$dataProvider=new CActiveDataProvider('Article', array(
			'pagination'=>false,
			'criteria'=>$criteria,
		));
	 
		$this->render('index',array(
			'dataProvider'=>$dataProvider,
		));
	}

	public function actionView(){
		
		$model = $this->loadModel();
		
		$this->render('view', array('model'=>$model));
	}
	
	private function loadModel()
	{
		if($this->_model===null)
		{
			if(isset($_GET['alias']))
				$this->_model=Article::model()->find('alias=:alias', array(':alias'=>$_GET['alias']));
			if($this->_model===null)
				throw new CHttpException(404,'The requested page does not exist.');
		}
		return $this->_model;
	}
	
	// -----------------------------------------------------------
	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}